using System.Drawing;
using System.Collections.Generic;
using FIRADriverLibrary;
using System;
using AGHFiraPlayer.Strategies;
using AGHFiraPlayer.Strategies.StrategyAdvisiors;
using GeometryCSharp;
using AGHFiraPlayer.PreviousDriver;

namespace AGHFiraPlayer
{
    public enum GameState
    {
        Off,
        StartupPositions,
        Play
    }
	/// <summary>
	/// 
	/// </summary>
	public class TheCoachOf5
	{
        private IStrategyAdvisor advisor;
        private List<IStrategy> strategies;

        //*****************************************TEST
        //dla testowania pojedynczych funkcjonalnosci
        //public RobotController robot;
        public FIRADriver firaDriver;
        public AGHDriver driver;
        //*****************************************TEST

		private GameState gameState = GameState.Off;
		public GameState GameState 
		{
			get { return gameState; }
			set {gameState = value; }
		}

        public TheCoachOf5(AGHDriver driver, RectangleF pitchArea, double goalWidth)
		{
            //*****************************************TEST
            this.driver = driver;
            advisor = new BasicStrategyAdvisor(driver);
            //*****************************************TEST

            driver.setStartPointsAndChooseGoalKeeper();
            //advisor = new BasicStrategyAdvisor(new AGHDriver(ref firaDriver, pitchArea, goalWidth));
		}

		public void Refresh()
		{
            driver.unassignFromStrategies();
			if (gameState == GameState.Off)
			{
                advisor.gameStateOff();
			}
			if (gameState == GameState.StartupPositions)
			{                 
                advisor.startupPositions();
			}
			if (gameState == GameState.Play)
			{
                strategies = advisor.advice();
                foreach (IStrategy strat in strategies)
                    strat.execute();
                driver.unassignFromStrategies();
                foreach (IStrategy strategy in strategies)
                {
                    strategy.clearCachedValues();
                }
                StrategiesManager.returnToPool(strategies);
			}
		}

        //*****************************************TEST
        public void test(RobotController robot) {
            Vector2D robotBallVector = new Vector2D(firaDriver.ballX - robot.robotState.x, firaDriver.ballY - robot.robotState.y);
            SimpleMovingFunctions.intersectBallTrajectory(robot, firaDriver);
        }

        public void test2(RobotController robot) {
            Vector2D robotBallVector = new Vector2D(firaDriver.ballX - robot.robotState.x, firaDriver.ballY - robot.robotState.y);
            SimpleMovingFunctions.intersectBallTrajectory(robot, firaDriver);
        }
        //*****************************************TEST
	}
}
